﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DTOTemplatedGenerator
{
    /// <summary>
    /// Interaction logic for EnterValueDlg.xaml
    /// </summary>
    public partial class EnterValueDlg : Window
    {
        private bool _multiRowText;
        public string Text
        {
            get
            {
                return _multiRowText ?
                    new TextRange(rtbValue.Document.ContentStart, rtbValue.Document.ContentEnd).Text :
                    tbValue.Text;
            }
        }

        public EnterValueDlg(string iniText = "", bool multiRowText = false)
        {
            InitializeComponent();            

            _multiRowText = multiRowText;

            if (multiRowText)
            {
                rtbValue.AppendText(iniText);                
                tbValue.Visibility = Visibility.Collapsed;
                rtbValue.Visibility = Visibility.Visible;
                rtbValue.SetValue(Paragraph.LineHeightProperty, 5.0);
                Height = 500;
                Width = 400;                
            }
            else
            {
                tbValue.Text = iniText;
                tbValue.Visibility = Visibility.Visible;
                rtbValue.Visibility = Visibility.Collapsed;
            }
        }

        private void onClose(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void onOk(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }        

        private void onDlgKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && _multiRowText == false)
            {
                DialogResult = true;
            }
            else if (e.Key == Key.Escape)
                DialogResult = false;
        }
    }
}
